package com.ymatou.iapi.exp.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.ymatou.iapi.exp.parameter.GetOverstepUserCountBean;
import com.ymatou.iapi.exp.service.GetOverstepUserCountCall;
import com.ymatou.iapi.exp.service.GetCoinConfigInfoCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.PrivilegeConfig;
import com.ymttest.database.sqlwapper.ExpWapper;

/**
 * 获取当前用户的经验值超出了多少个用户 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetCoinConfigInfo {
	private static GetCoinConfigInfoCall GetCoinConfigInfoCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取等级与特权的映射关系");
	}

	@Before
	public void caseUp() {
		GetCoinConfigInfoCall = new GetCoinConfigInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(GetCoinConfigInfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GetCoinConfigInfo_001() {
		Logger.start(true, "获取金币配置");
		try {
			ExpWapper ExpWapper = new ExpWapper();
			GetCoinConfigInfoCall.callService();
			JsonObject result = GetCoinConfigInfoCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", GetCoinConfigInfoCall.getString("BCode"), "验证BCode");
			result.get("configList").getAsJsonArray().forEach(cionconfig -> {
				// Logger.debug(cionconfig.getAsJsonObject().get("config").toString());
				String bizCode = cionconfig.getAsJsonObject().get("bizCode").toString();
				//格式化参数
				String[] confs = cionconfig.getAsJsonObject().get("config").toString().replaceAll(Pattern.quote("\":\""), "=").replaceAll(Pattern.quote("{\""), "")
						.replaceAll(Pattern.quote("\"}"), "").split(Pattern.quote("\",\""));
				String dbconf = ExpWapper.selectCoinBizcodeConfig(bizCode).get(0).getConfigValue();
				for (String conf : confs) {
					Logger.verifyIsContains(conf, dbconf, "验证conf");
				}
				
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}